package com.googlecode.bip;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Part;
import cx.ath.choisnet.util.iterator.IteratorHelper;

/**
 * Fake/limited implement of HttpServletRequest
 *
 * @author Claude CHOISNET
 */
public class MockHttpServletRequest implements HttpServletRequest
{
    private Map<String,Object> attributeMap = new HashMap<String,Object>();
    private String remoteUser;
    private AsyncContext asyncContext;
    private Map<String, String[]> parameterMap  = new HashMap<String,String[]>();;

    //---------------------------------------------------------------

    @Override
    public String getRemoteUser()
    {
        return remoteUser;
    }

    public void setRemoteUser( final String remoteUser )
    {
        this.remoteUser = remoteUser;
    }

    //---------------------------------------------------------------

    @Override
    public Object getAttribute( String name )
    {
        return attributeMap.get( name );
    }

    @Override
    public Enumeration<String> getAttributeNames()
    {
        return IteratorHelper.toEnumeration( attributeMap.keySet().iterator() ) ;
    }

    @Override
    public void setAttribute( String name, Object value )
    {
        attributeMap.put( name, value );
    }

    @Override
    public void removeAttribute( String name )
    {
        attributeMap.remove( name );
    }

    //---------------------------------------------------------------

    @Override
    public AsyncContext getAsyncContext()
    {
        return asyncContext;
    }

    public void setAsyncContext( final AsyncContext asyncContext )
    {
        this.asyncContext = asyncContext;
    }

    @Override
    public AsyncContext startAsync() throws IllegalStateException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
        //return asyncContext;
    }

    @Override
    public AsyncContext startAsync( ServletRequest request, ServletResponse response )
        throws IllegalStateException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
        //return asyncContext;
    }

    @Override
    public String getParameter( String name )
    {
        String[] values = parameterMap.get( name );

        if( values != null && values.length > 0 ) {
            return values[ 0 ];
            }

        return null;
    }

    @Override
    public boolean isAsyncStarted()
    {
        return false;
    }

    @Override
    public boolean isAsyncSupported()
    {
        return false;
    }

    //---------------------------------------------------------------

    public void addParameter( String name, String...values )
    {
        parameterMap.put( name, values );
    }

    @Override
    public Map<String,String[]> getParameterMap()
    {
        return parameterMap;
    }

    @Override
    public Enumeration<String> getParameterNames()
    {
        return IteratorHelper.toEnumeration( parameterMap.keySet().iterator() );
    }

    @Override
    public String[] getParameterValues( String name )
    {
        return parameterMap.get( name );
    }

    //---------------------------------------------------------------




    @Override
    public String getCharacterEncoding()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public int getContentLength()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getContentType()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public DispatcherType getDispatcherType()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public ServletInputStream getInputStream() throws IOException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getLocalAddr()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getLocalName()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public int getLocalPort()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Locale getLocale()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Enumeration<Locale> getLocales()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getProtocol()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public BufferedReader getReader() throws IOException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    @Deprecated
    public String getRealPath( String arg0 )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getRemoteAddr()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getRemoteHost()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public int getRemotePort()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public RequestDispatcher getRequestDispatcher( String arg0 )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getScheme()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getServerName()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public int getServerPort()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public ServletContext getServletContext()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isSecure()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public void setCharacterEncoding( String arg0 )
            throws UnsupportedEncodingException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean authenticate( HttpServletResponse arg0 )
            throws IOException, ServletException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getAuthType()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getContextPath()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Cookie[] getCookies()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public long getDateHeader( String arg0 )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getHeader( String arg0 )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Enumeration<String> getHeaderNames()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Enumeration<String> getHeaders( String arg0 )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public int getIntHeader( String arg0 )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getMethod()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Part getPart( String arg0 ) throws IOException, ServletException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Collection<Part> getParts() throws IOException, ServletException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getPathInfo()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getPathTranslated()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getQueryString()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getRequestURI()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public StringBuffer getRequestURL()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getRequestedSessionId()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public String getServletPath()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public HttpSession getSession()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public HttpSession getSession( boolean arg0 )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public Principal getUserPrincipal()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isRequestedSessionIdFromCookie()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isRequestedSessionIdFromURL()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    @Deprecated
    public boolean isRequestedSessionIdFromUrl()
    {
        return isRequestedSessionIdFromURL();
    }

    @Override
    public boolean isRequestedSessionIdValid()
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isUserInRole( String rolename )
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public void login( String username, String password ) throws ServletException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

    @Override
    public void logout() throws ServletException
    {
        // XTODO UnsupportedOperationException
        throw new UnsupportedOperationException();
    }

}
